package cn.lsc.basic.service.impl;

import cn.lsc.basic.controller.util.PageList;
import cn.lsc.basic.domain.BaseDomain;
import cn.lsc.basic.mapper.BaseMapper;
import cn.lsc.basic.query.BaseQuery;
import cn.lsc.basic.service.IBaseService;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public void add(T t) {
        mapper.save(t);
    }

    @Override
    public void del(Long id) {
        mapper.remove(id);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public T findById(Long id) {
        return mapper.loadById(id);
    }

    @Override
    public List<T> findAll() {
        return mapper.loadAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery<BaseDomain> query) {
        Long count = mapper.queryCount(query);
        List<T> Ts = mapper.queryData(query);



        return new PageList<T>(count,Ts);
    }

    @Override
    public void patchDelete(List<Long> ids) {
        mapper.patchDelete(ids);
    }
}
